<?php 
class Model_author extends CI_Model{

	function __construct(){
		parent::__construct();
	}
	//Dem tong so luong ban ghi trong bang author
	function get_total_author(){
		$query = $this->db->get("tbl_author");
		return $query->num_rows();
	}
	//Lay tat ca danh sach author
	function get_all_author($offset,$limit){
		$this->db->select("*");
		$this->db->order_by("author_id","DESC");
		$this->db->limit($offset,$limit);
		$query = $this->db->get("tbl_author");
		return $query->result_array();
	}
	//Them du lieu
	function insert($data){
		return $this->db->insert("tbl_author",$data);
	}
	//kiem tra su ton tai cua tac gia
	function get_info_author($author_name){
		$this->db->select("*");
		$this->db->where("author_name",$author_name);
		$query = $this->db->get("tbl_author");
		return $query->row_array();
	}
	//Cap nhat thong tin tac gia
	function update($id,$data){
		$this->db->where("author_id",$id);
		return $this->db->update("tbl_author",$data);
	}
	//Lay thong tin tac gia theo id
	function get_info_author_by_id($id){
		$this->db->where("author_id",$id);
		$query = $this->db->get("tbl_author");
		return $query->row_array();
	}
	//Xoa thong tin tac gia
	function delete($id){
		$this->db->where("author_id",$id);
		$this->db->delete("tbl_author");
	}
	//tim kiem thong tin tac gia
	function search($keyword,$offset,$limit){
		$this->db->like("author_name",$keyword);
		$this->db->limit($offset,$limit);
		$query = $this->db->get("tbl_author");
		return $query->result_array();
	}
	//lay tong so luong ban ghi tim kiem thong tin tac gia
	function count_search($keyword){
		$this->db->like("author_name",$keyword);
		$query = $this->db->get("tbl_author");
		return $query->num_rows();
	}
}
?>